package com.hz.pay.center.controller;

import com.hz.pay.center.exception.BizException;
import com.hz.pay.center.service.IRefundService;
import com.pay.common.req.RefundReq;
import com.pay.common.resp.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 退款接口
 */
@RestController
public class RefundController {


    @Autowired
    private IRefundService refundService;

    /**
     * 统一退款接口
     * @return
     */
    @RequestMapping(value = "/refund/create",method = RequestMethod.POST)
    public Response<?> refund(@RequestBody RefundReq refundReq){

        // TODO 参数校验，转发请求，返回对象



        //兼容，同步，支付宝。发送退款，马上获取到退款结果

        // 异步，微信， 发起退款，返回退款受理中，需要调用查询接口。去查询退款状态

        try{
            refundService.doRefund(refundReq);

            return new Response<>();
        }catch (BizException e){
            return Response.returnFail(e.getMessage());
        }


    }
}
